$title Minimal

* -----------------------------------------------------------------------------------
* Simplified CGE model in %-change like ORANI-G, but with only 7 sectors,
* a simplified treatment of taxes, and no margins or multiproduction.
* Laurent Cretegny, CoPS, Monash University, Australia, 2004.
* -----------------------------------------------------------------------------------

sets
  user              all users
  ind(user)         industries and commodities
  src               source of commodities
  fac               primary factors;

alias (ind,s), (s,o);

parameters
  factor(fac,s)     wages and profits [[1fac:fac*ind]]
  use(o,src,user)   use matrix [[use:o*src*user]]
  v1ptx(s)          production tax revenue [[1ptx:ind]]
  v0mtx(o)          import tax revenue [[0tar:o]]
  sigma(o)          Armington elasticities [[sigm:o]]
  sigma1prim(s)     primary factor substitution elasticity [[sgm1:s]]
  exp_elast(o)      export demand elasticities [[expl:o]];

$gdxin minimal
* [22/06/04] ? Need to add bpw, bc, brw since are needed on GEMPACK HAR file 
* ?? $load user ind src fac factor use v1ptx v0mtx sigma sigma1prim exp_elast bpw bc brw
$load user ind src fac factor use v1ptx v0mtx sigma sigma1prim exp_elast
$gdxin

parameters
  interm(o,s)       intermediate demand [[intr:o*s]]
  intdom(o,s)       intermediate demand for domestic good [[intd:o*s]]
  intimp(o,s)       intermediate demand for import [[intm:o*s]]
  demdom(o)         private demand for domestic good [[dmdm:o]]
  demimp(o)         private demand for import [[dmmp:o]]
  invdom(o)         investment demand for domestic good [[inv1:o]]
  invimp(o)         investment demand for import [[invm:o]]
  govdom(o)         government demand for domestic good [[gvd1:o]]
  govimp(o)         government demand for import [[gvmp:o]]
  va(s)             value-added [[va:s]]
  labour(s)         labour [[labr:s]]
  capital(s)        capital [[cptl:s]]
  output(s)         domestic production [[otpt:s]]
  demand(o)         private demand [[dmnd:o]]
  invdem(o)         investment demand [[invd:o]]
  govdem(o)         government demand [[gvdm:o]]
  invest            investment [[invs:]]
  expend            household expenditure [[expn:]]
  govexp            government expenditure [[gvxp:]]
  export(o)         exports [[expr:o]]
  import(o)         imports (net of tariff) [[impr:o]]
  bty(s)            production tax rate [[bty:s]]
  btm(o)            import tariff rate [[btm:o]]
  bpy(s)            production price
  bpm(o)            import price [[bpm:o]]
  bpw               world price
  bbop              balance of payments (surplus) [[bbop:]]
  bc                consumption
  brw               real wage
  epli              benchmark employment index [[epl:]]
  efxi              benchmark total exports in foreign exchange index [[efx:]]
  ei(o)             benchmark export index [[e:o]]
  bopi              benchmark balance of payments index [[bop:]];

interm(o,s) = sum(src, use(o,src,s));

demand(o) = sum(src, use(o,src,'hh'));
invdem(o) = sum(src, use(o,src,'inv'));
govdem(o) = sum(src, use(o,src,'gov'));

intdom(o,s) = use(o,'dom',s);
intimp(o,s) = use(o,'imp',s);

demdom(o) = use(o,'dom','hh');
demimp(o) = use(o,'imp','hh');

invdom(o) = use(o,'dom','inv');
invimp(o) = use(o,'imp','inv');

govdom(o) = use(o,'dom','gov');
govimp(o) = use(o,'imp','gov');

va(s) = sum(fac, factor(fac,s));
labour(s) = factor('lab',s);
capital(s) = factor('cap',s);

output(s) = sum(o, interm(o,s)) + va(s) + v1ptx(s);
bty(s) = v1ptx(s) / output(s);
bpy(s) = 1 - bty(s);

expend = sum(o, demand(o));
invest = sum(o, invdem(o));
govexp = sum(o, govdem(o));

export(o) = use(o,'dom','exp');
import(o) = sum(user, use(o,'imp',user)) - v0mtx(o);
btm(o)$import(o) = v0mtx(o) / import(o);
bpw(o) = 1;
bpm(o) = bpw(o) * (1 + btm(o));
bbop = sum(o, export(o) - import(o));

bc = 1;
brw = 1;

epli = 1;
efxi = sum(o, export(o));
ei(o) = 1;
bopi = 1;

$if not exist minimal.har $include gdxtohar

$ontext
$model:minimal

$sectors:
  y(s)                        ! production
  a(o,s)$interm(o,s)          ! Armington index for intermediate demand
  ac(o)$demand(o)             ! Armington index for private demand
  aj(o)$invdem(o)             ! Armington index for investment
  ag(o)$govdem(o)             ! Armington index for government demand
  v(s)                        ! value-added
  m(o)                        ! import index
  c                           ! household consumption
  j                           ! aggregate investment
  g                           ! government demand

$commodities:
  pd(o)                       ! domestic price of output
  pa(o,s)$interm(o,s)         ! Armington price index for intermediate demand
  pac(o)$demand(o)            ! Armington price index for private demand
  paj(o)$invdem(o)            ! Armington price index for investment
  pag(o)$govdem(o)            ! Armington price index for government demand
  pv(s)                       ! price index for value-added
  pl                          ! price of labour (wage rate)
  pk(s)                       ! price of capital (sector specific)
  pm(o)                       ! price of imports
  pfx                         ! real exchange rate
  pc                          ! consumer price index
  pj                          ! price of a unit of investment
  pg                          ! price of a unit of government output

$consumers:
  ra                          ! representative agent

$auxiliary:
  epl                         ! employment index
  e(o)                        ! export index
  efx                         ! total exports in foreign exchange
  bop                         ! balance of payments index (surplus)
*  upl                         ! unemployment index

$prod:y(s)          s:0.0                         ! Excerpt 6, 9 : E_p1tot, E_pA
  o:pd(s)           q:output(s)         p:bpy(s)  a:ra      t:bty(s)
  i:pa(o,s)         q:interm(o,s)    
  i:pv(s)           q:va(s)

$prod:a(o,s)$interm(o,s)      s:sigma(o)        ! Excerpt 4 : E_p_s
  o:pa(o,s)         q:interm(o,s)
  i:pd(o)           q:intdom(o,s)
  i:pm(o)           q:intimp(o,s)

$prod:ac(o)$demand(o)         s:sigma(o)        ! Excerpt 4 : E_p_s
  o:pac(o)          q:demand(o)
  i:pd(o)           q:demdom(o)
  i:pm(o)           q:demimp(o)

$prod:aj(o)$invdem(o)         s:sigma(o)        ! Excerpt 4 : E_p_s
  o:paj(o)          q:invdem(o)
  i:pd(o)           q:invdom(o)
  i:pm(o)           q:invimp(o)

$prod:ag(o)$govdem(o)         s:sigma(o)        ! Excerpt 4 : E_p_s
  o:pag(o)          q:govdem(o)
  i:pd(o)           q:govdom(o)
  i:pm(o)           q:govimp(o)

$prod:v(s)          s:sigma1prim(s)               ! Excerpt 5 : E_p1prim
  o:pv(s)           q:va(s)
  i:pl              q:labour(s)
  i:pk(s)           q:capital(s)

$prod:m(o)                                        ! Excerpt 10 : E_pB
  o:pm(o)           q:(import(o)*bpm(o))
  i:pfx             q:import(o)         p:bpm(o)  a:ra      t:btm(o)

$prod:c             s:1.0                         ! Excerpt 7 : E_p3tot
  o:pc              q:expend
  i:pac(o)          q:demand(o)

$prod:j
  o:pj              q:invest
  i:paj(o)          q:invdem(o)

$prod:g
  o:pg              q:govexp
  i:pag(o)          q:govdem(o)

$demand:ra
  d:pc
  e:pl              q:(sum(s, labour(s)))         r:epl
  e:pk(s)           q:capital(s)
  e:pj              q:-invest                     ! Closure : agg. investment fixed
  e:pg              q:-govexp                     ! Closure : gov. demand fixed
  e:pfx             q:1                           r:efx
  e:pd(o)           q:-export(o)                  r:e(o)
  e:pfx             q:-bbop                       r:bop
*  e:pl              q:(-sum(s, labour(s)))        r:upl

$constraint:e(o)                                  ! Excerpt 8 : E_x4a
  e(o) =e= (pd(o) / (pfx*bpw(o)))**(-exp_elast(o));

$constraint:efx
  efx =e= sum(o, e(o)*export(o));

$constraint:bop                                   ! Closure : bal. of payments free
  c =e= bc;                                       ! Closure : consumption fixed

$constraint:epl                                   ! Closure : employment level free
  pl =e= brw * pc;                                ! Closure : real wage fixed

$report:
  v:cons(o)         i:pac(o)            prod:c

$offtext
$sysinclude mpsgeset minimal

* Initialize levels on auxiliary variables

*upl.lo = -inf;
bop.lo = -inf;

epl.l = epli;
*upl.l = upli;
bop.l = bopi;

e.l(o) = ei(o);
efx.l = efxi;

* Fixation of the exchange rate as the numeraire

pfx.fx = 1;

* Benchmark replication

minimal.iterlim = 0;
$include minimal.gen
solve minimal using mcp;
abort$(abs(minimal.objval) gt 1e-4) '*** minimal does not calibrate ! ***';
minimal.iterlim = 10000;

* Counterfactual (10% increase in consumption)

bc = bc * 1.1;
demand(o) = demand(o) * 1.1;
$include minimal.gen
solve minimal using mcp;

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com('output',o) = (y.l(o) - 1) * 100;
res_com('cons',o)$demand(o) = (cons.l(o)/demand(o) - 1) * 100;
res_com('import',o) = (m.l(o) - 1) * 100;
res_com('export',o) = (e.l(o) - 1) * 100;
res_com('price',o) = (pd.l(o) - 1) * 100;

res_agg('ra_inc') = (ra.l/expend - 1 ) * 100;
res_agg('employ') = (epl.l - 1) * 100;

option decimals = 6;
display res_com, res_agg;
